
package dbconnect;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Tuyen
 */
public class DBConnect implements DbInterface{
    private Connection conn;
    private Statement state;
    private ResultSet result;

    public DBConnect() {
    }

    public DBConnect(String host,String port,String Dbname,String hostID,String pass) {
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn=DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+Dbname,hostID,pass);
            state=conn.createStatement();
        }catch(ClassNotFoundException | SQLException e){
            System.out.println("Error-"+e);
        }
    }
     
    @Override
    public void getConnect(String host,String port,String dbName,String hostid,String pass)throws RemoteException{
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn=DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+dbName,hostid,pass);
            state=conn.createStatement();
        }catch(ClassNotFoundException | SQLException e){
            System.out.println("Error-"+e);
        }
    }

    @Override
    public ResultSet getData() throws SQLException{
        try{
           String sql="select*from user";
           result=state.executeQuery(sql);
        }catch(Exception e){
            System.out.println("Error");
        }
        return result;
    }
}
